package net.thread;

import java.io.File;

public class ListCallbackDigestUserInterface implements DigestListener
{
	
	private File	input;
	private byte[]	digest;
	
	@Override
	public void digestCalculated(byte[] digest)
	{
		this.digest = digest;
		System.out.println(this);
	}
	
	public ListCallbackDigestUserInterface(File f)
	{
		this.input = f;
	}
	
	public void calculateDigest()
	{
		ListCallbackDigest cd = new ListCallbackDigest(input);
		cd.addDigestListener(this);
		Thread t = new Thread(cd);
		t.start();
	}
	
	@Override
	public String toString()
	{
		
		String result = input.getName();
		if (digest != null)
		{
			for (int i = 0; i < digest.length; i++)
			{
				result += digest[i] + " ";
			}
			return result;
		}
		else
		{
			return "not avaliable";
		}
	}
	
	public static void main(String[] args)
	{
		for (int i = 0; i < args.length; i++)
		{
			File f = new File(args[i]);
			ListCallbackDigestUserInterface d = new ListCallbackDigestUserInterface(f);
			d.calculateDigest();
		}
	}
}
